<template>
  <div>
    <a-table
      ref="table"
      size="middle"
      bordered
      rowKey="id"
      class="j-table-force-nowrap"
      :scroll="{ x: true }"
      :columns="inspectionColumns"
      :dataSource="inspectionList"
    >
      <template slot="action" slot-scope="text, record">
        <a @click="inspectionDetail(record)">详情</a>
      </template>
    </a-table>
    <qc-plan-report-modal ref="inspectionForm" />
  </div>
</template>

<script>
import '@/assets/less/TableExpand.less'
import { getAction } from '@api/manage'
import QcPlanReportModal from '@/views/qms/plan/modules/QcPlanReportModal.vue'

export default {
  name: 'inspection',
  components: { QcPlanReportModal },
  data() {
    return {
      description: '检验信息',
      inspectionList: [],
      inspectionColumns: [
        {
          title: '#',
          dataIndex: '',
          key: 'rowIndex',
          width: 60,
          align: 'center',
          customRender: function (t, r, index) {
            return parseInt(index) + 1
          },
        },
        {
          title: '检验单号',
          align: 'center',
          dataIndex: 'reportNumber',
        },
        {
          title: '计划单号',
          align: 'center',
          dataIndex: 'planNumber',
        },
        {
          title: '生产车间',
          align: 'center',
          dataIndex: 'productionShop_dictText',
        },
        {
          title: '执行日期',
          align: 'center',
          dataIndex: 'executionDate',
          customRender: function (text) {
            return !text ? '' : text.length > 10 ? text.substr(0, 10) : text
          },
        },
        {
          title: '抽检数量',
          align: 'center',
          dataIndex: 'samplingQuantity',
        },
        {
          title: '检验结果',
          align: 'center',
          dataIndex: 'inspectionResult_dictText',
        },
        {
          title: '检验员',
          align: 'center',
          dataIndex: 'createBy_dictText',
        },
        {
          title: '检验部门',
          align: 'center',
          dataIndex: 'sysOrgCode_dictText',
        },
        {
          title: '检验日期',
          align: 'center',
          dataIndex: 'inspectionDate',
          customRender: function (text) {
            return !text ? '' : text.length > 10 ? text.substr(0, 10) : text
          },
        },
        {
          title: '操作',
          dataIndex: 'action',
          align: 'center',
          fixed: 'right',
          width: 70,
          scopedSlots: { customRender: 'action' },
        },
      ],
      url: {
        inspection: '/qms/inspection/plan/report/allList',
      },
    }
  },

  methods: {
    loadInspectionData(batchNumber, reportType) {
      this.inspectionList = []
      if (batchNumber && reportType) {
        getAction(this.url.inspection, { batchNumber: batchNumber, reportType: reportType }).then((res) => {
          if (res.success) {
            this.inspectionList = res.result.records || res.result || []
          }
        })
      }
    },
    inspectionDetail: function (record) {
      this.$refs.inspectionForm.detail(record)
      this.$refs.inspectionForm.title = '详情'
      this.$refs.inspectionForm.disableSubmit = true
      this.$refs.inspectionForm.reportType = record.reportType
    },
  },
}
</script>
<style scoped>
@import '~@assets/less/common.less';
::v-deep .ant-table-tbody tr {
  height: 36px !important;
}
</style>
